﻿// -----------------------------------------------------------------------
// <copyright file="MainForm.cs" company="Abyssalsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Gui.Player.Main
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using Core.Player;
    using Metal.Config;

    /// <summary>
    /// Main form (for audio)
    /// </summary>
    public partial class MainForm : Gui.BaseForm.BaseForm
    {
        #region Members

        ///// <summary>Our video form</summary>
        //private Form video;

        #endregion

        #region Constructor

        public MainForm(string shellFile) : this()
        {
            // Play shell file
            if (shellFile != null)
            {
                Core.Player.Playback.Instance.Open(shellFile);
                Core.Player.Playback.Instance.Play();
            }
        }

        /// <summary>
        /// Initializes a new instance of the MainForm class.
        /// </summary>
        public MainForm()
        {
            try
            {
                this.InitializeComponent();

                // Sets the icon of the application (this window is shown in the taskbar)
                this.Icon = new System.Drawing.Icon(Metal.Config.Paths.IconsFolder + "metal-player.ico");

                this.ApplyTheme();

                // Subscribe to menu items click event
                if (this.Controls["MenuItems"] != null)
                {
                    (this.Controls["MenuItems"] as Controls.MetalTopMenu).OnMenuClickEvent += new EventHandler(this.OnMenuClick);
                }
            }
            catch (Exception ex)
            {
                Metal.User.UserMessage.ShowError(ex);
            }
        }

        #endregion

        #region Events

        /// <summary>
        /// This event occurs when the user clicks on a menu, and calls by reflection the desired method
        /// </summary>
        /// <param name="sender">Object sender</param>
        /// <param name="e">Event args</param>
        private void OnMenuClick(object sender, EventArgs e)
        {
            try
            {
                ToolStripMenuItem control = (ToolStripMenuItem)sender;
                string methodName = control.Name;

                Type thisType = typeof(Metal.Player.Main.MainLogic);
                System.Reflection.MethodInfo theMethod = thisType.GetMethod(methodName, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
                if (theMethod != null)
                {
                    theMethod.Invoke(Metal.Player.Main.MainLogic.Instance, null);
                }
            }
            catch (Exception ex)
            {
                Metal.User.UserMessage.ShowError(ex);
            }
        }

        #endregion
    }
}
